<?php
$connect = mysqli_connect('localhost', 'root', 'root', 'thinkcmf');

if (!$connect) {
    echo jsonReturn(2, '数据库连接失败');
    exit;
}

$sql = "select s.name,count(major_name) as majorNum 
        from cmf_school as s 
        join cmf_major as m on m.school_id = s.id 
        group by s.name";

$query = mysqli_query($connect, $sql);

$data = mysqli_fetch_all($query, MYSQLI_ASSOC);

// 存放坐标轴名称
$nameArr = [];
// 存放数量
$numArr = [];

foreach ($data as $v) {
    array_push($nameArr, $v['name']);
    array_push($numArr, $v['majorNum']);
}

$arr = [
    'code' => 1,
    'msg' => 'Ok',
    'data' => [
        'schoolName' => $nameArr,
        'majorNum' => $numArr
    ]
];

echo json_encode($arr);